﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using GBlog.Core.Service;
using System.Web.Mvc;

namespace GBlog.Core.Modules
{
    public class ConfigModule : IHttpModule
    {
        DateTime FileModificationTime;

        public void Dispose() { }
        public void Init(HttpApplication context)
        {
            context.BeginRequest += this.OnBeginRequest;
            FileModificationTime = DependencyResolver.Current.GetService<IConfigService>().FileModificationTime;
        }

        public void OnBeginRequest(object s, EventArgs e)
        {
            IConfigService service = DependencyResolver.Current.GetService<IConfigService>();
            if (FileModificationTime != service.FileModificationTime)
            {
                DependencyResolver.Current.GetService<ISystemService>().Restart();
            }
        }
    }
}